package com.yizhiliulianta.movie.domain.service.impl;

import com.alibaba.fastjson.JSON;
import com.yizhiliulianta.movie.common.entity.UserInfo;
import com.yizhiliulianta.movie.common.rpc.UserRpc;
import com.yizhiliulianta.movie.common.util.LoginUtil;
import com.yizhiliulianta.movie.domain.bo.MovieBO;
import com.yizhiliulianta.movie.domain.convert.MovieBOConverter;
import com.yizhiliulianta.movie.domain.service.MovieDomainServcie;
import com.yizhiliulianta.movie.infra.entity.TMovie;
import com.yizhiliulianta.movie.infra.service.TMovieService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
@Slf4j
public class MovieDomainServiceImpl implements MovieDomainServcie{

    @Resource
    private TMovieService movieService;

    @Resource
    private UserRpc userRpc;

    @Override
    public MovieBO selectMovie(MovieBO movieBO) {
        TMovie tmovie = MovieBOConverter.INSTANCE.convertBoToMovie(movieBO);
        TMovie movie = movieService.queryById(tmovie.getId());

        String loginId = LoginUtil.getLoginId();
        UserInfo userInfo = userRpc.getUserInfo(loginId);
        log.info("用户为:{}",userInfo.getNickName());

        MovieBO bo = MovieBOConverter.INSTANCE.convertToMovieBO(movie);
        if (log.isInfoEnabled()) {
            log.info("MovieController.selectMovie.bo:{}",
                    JSON.toJSONString(bo));
        }
        return bo;
    }
}
